<template>
  <div>
    <el-table :data="List">
      <el-table-column prop="_id" width="140"></el-table-column>
      <el-table-column prop="name" label="昵称" width="140"></el-table-column>
      <el-table-column prop="url" label="链接" width="120"></el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button
            @click="$router.push(`/friendships/edit/${scope.row._id}`)"
            type="text"
            size="small"
          >编辑</el-button>
          <el-button @click="remove(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      List: [],
    };
  },
  methods: {
    // 获取友链列表
    async getList() {
      const res = await this.$http.get("/friendship");
      this.List = res.data;
    },
    // 删除友链
    remove(row) {
      this.$confirm(`是否删除友链 '${row.name}'`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const res = await this.$http.delete(`/friendship/${row._id}`);
        this.$message({
          type: "success",
          message: "删除成功!",
        });
        this.getList();
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>

<style>
</style>